﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Northwind.Objects
{
    public class Product : INotifyPropertyChanged
    {
        // ProductID
        private int _ProductID;
        public int ProductID
        {
            get { return _ProductID; }
            set
            {
                if (_ProductID != value)
                {
                    _ProductID = value;
                    OnPropertyChanged("ProductID");
                }
            }
        }
        // ProductName
        private string _ProductName;
        public string ProductName
        {
            get { return _ProductName; }
            set
            {
                if (_ProductName != value)
                {
                    _ProductName = value;
                    OnPropertyChanged("ProductName");
                }
            }
        }
        // QuantityPerUnit
        private string _QuantityPerUnit;
        public string QuantityPerUnit
        {
            get { return _QuantityPerUnit; }
            set
            {
                if (_QuantityPerUnit != value)
                {
                    _QuantityPerUnit = value;
                    OnPropertyChanged("QuantityPerUnit");
                }
            }
        }
        // UnitPrice
        private decimal _UnitPrice;
        public decimal UnitPrice
        {
            get { return _UnitPrice; }
            set
            {
                if (_UnitPrice != value)
                {
                    _UnitPrice = value;
                    OnPropertyChanged("UnitPrice");
                }
            }
        }
        // UnitsInStock
        private int _UnitsInStock;
        public int UnitsInStock
        {
            get { return _UnitsInStock; }
            set
            {
                if (_UnitsInStock != value)
                {
                    _UnitsInStock = value;
                    OnPropertyChanged("UnitsInStock");
                }
            }
        }
        // UnitsOnOrder
        private int _UnitsOnOrder;
        public int UnitsOnOrder
        {
            get { return _UnitsOnOrder; }
            set
            {
                if (_UnitsOnOrder != value)
                {
                    _UnitsOnOrder = value;
                    OnPropertyChanged("UnitsOnOrder");
                }
            }
        }
        // ReorderLevel
        private int _ReorderLevel;
        public int ReorderLevel
        {
            get { return _ReorderLevel; }
            set
            {
                if (_ReorderLevel != value)
                {
                    _ReorderLevel = value;
                    OnPropertyChanged("ReorderLevel");
                }
            }
        }
        // Discontinued
        private bool _Discontinued = false;
        public bool Discontinued
        {
            get { return _Discontinued; }
            set
            {
                if (_Discontinued != value)
                {
                    _Discontinued = value;
                    OnPropertyChanged("Discontinued");
                }
            }
        }

        #region Constructor
        public Product()
        { }

        public Product(string sText)
        {
            try
            {
                if (!string.IsNullOrEmpty(sText))
                {
                    string[] M = sText.Split(new char[] { ',' }, StringSplitOptions.None);
                    int iTemp;
                    if (int.TryParse(M[0], out iTemp))
                    {
                        ProductID = iTemp;
                    }
                    ProductName = M[1];
                    QuantityPerUnit = M[2];
                    decimal dTemp;
                    if (decimal.TryParse(M[3], out dTemp))
                    {
                        UnitPrice = dTemp;
                    }
                    if (int.TryParse(M[4], out iTemp))
                    {
                        UnitsInStock = iTemp;
                    }
                    if (int.TryParse(M[5], out iTemp))
                    {
                        UnitsOnOrder = iTemp;
                    }
                    if (int.TryParse(M[6], out iTemp))
                    {
                        ReorderLevel = iTemp;
                    }
                    bool bTemp;
                    if (bool.TryParse(M[7], out bTemp))
                    {
                        Discontinued = bTemp;
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
        #endregion Constructor End

        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string pPropertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(pPropertyName));
            }
        }
    }

    public class Category
    {
        public string CategoryName { get; set; }
        public string Description { get; set; }
        public byte[] Picture { get; set; }
    }
}
